package com.project.internship.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.internship.entity.Class;
import com.project.internship.mapper.ClassMapper;
import com.project.internship.service.ClassService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.internship.utils.YearUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2020-04-07
 */
@Service
public class ClassServiceImpl extends ServiceImpl<ClassMapper, Class> implements ClassService {

    @Autowired
    ClassMapper classMapper;

    @Override
    public List<Class> getClasses(Integer id) {
        String key = YearUtils.getCurrentYear();
        int num = Integer.parseInt(key);
        key = String.valueOf(num - 3).substring(2);

        return classMapper.getClasses(id,key);
    }

    @Override
    public List<Class> getAllClasses(Integer requiredId) {
        QueryWrapper<Class> wrapper = new QueryWrapper<>();
        wrapper.select("id","name")
                .eq("major_id",requiredId)
                .orderByDesc("name");
        return classMapper.selectList(wrapper);
    }

    @Override
    public Integer addClass(Class aClass) {
        return classMapper.insert(aClass);
    }

    @Override
    public Integer deleteClass(Integer id) {
        return classMapper.deleteById(id);
    }
}
